const api = require('../../api/api');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    searchContainer: '',
    filmClass: [],
  },

  // 点击搜索框跳转页面
  searchtap(e) {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },

  // onReady: function () {
  //   this.loadCinemaHit();
  //   this.loadRecentHits();
  //   this.loadFreeOnline();
  // },

  onShow() {
    this.loadCinemaHit();
    this.loadRecentHits();
    this.loadFreeOnline();
  },

  // 加载影院热映数据
  async loadCinemaHit() {
    const data = await api.cinemaHit({
      start: 0,
      count: 6
    });
    let CinemaHitInfo = {
      id: data.subject_collection.id,
      title: data.subject_collection.name,
      list: data.subject_collection_items
    }
    this.setData({
      'filmClass[0]': CinemaHitInfo
    })
  },

  // 加载近期热门
  async loadRecentHits() {
    const data = await api.recentHits({
      start: 0,
      count: 6
    });
    let RecentHitsInfo = {
      id: data.subject_collection.id,
      title: data.subject_collection.name,
      list: data.subject_collection_items
    }
    this.setData({
      'filmClass[1]': RecentHitsInfo
    })
  },

  // 加载免费在线
  async loadFreeOnline() {
    const data = await api.freeOnline({
      start: 0,
      count: 6
    });
    let FreeOnlineInfo = {
      id: data.subject_collection.id,
      title: data.subject_collection.name,
      list: data.subject_collection_items
    }
    this.setData({
      'filmClass[2]': FreeOnlineInfo
    })
  },
  // 点击证照信息
  licence() {
    wx.showToast({
      title: '个人开发，无证照信息',
      icon: 'none'
    })
  }
})